#ifndef VSCONTROLLER_H
#define VSCONTROLLER_H
#include "VSObject.h"
namespace VSEngine2
{
	class VSStream;
	class VSGRAPHIC_API VSController : public VSObject
	{
		//RTTI
		DECLARE_RTTI;
	public:
		virtual ~VSController() = 0;
		inline VSObject * GetObject()const;
		virtual bool Update(double dAppTime);
		virtual bool UpdateEx(double aAppTime);
		enum // Repeat Type
		{
			RT_NONE,
			RT_CLAMP,
			RT_WRAP,
			RT_CYCLE,
			RT_MAX
		};
// 		enum //Update Type
// 		{
// 			UT_FORWARD,
// 			UT_BACKWARD,
// 			UT_MAX
// 		};
		unsigned int m_uiRepeatType;
//		unsigned int m_uiUpdateType;
		double		m_dMinTime;
		double		m_dMaxTime;
		double		m_dPhase;
		double		m_dFrequency;
		
		static double GetTime(double fTime, double fMin,double fMax,unsigned int uiRepeatType);
	public:
		friend class VSObject;
		VSController();
		virtual bool SetObject(VSObject * pObject);
		double	GetControlTime(double dAppTime);

		VSObject* m_pObject;
		double	m_dNowAppTime;
		double	m_dLastAppTime;
		double  m_dIntervalTime;
		double	m_dTimeSum;
		double	m_dStartSystemTime;
		bool	m_bStart;

		inline void ClearTime();
	public:

		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
		virtual bool Link(VSStream & rStream);

		virtual bool Register(VSStream & rStream)const;
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);
	public:
		bool m_bEnable;
	};
#include "VSController.inl"
typedef VSPointer<VSController> VSControllerPtr;

}
#endif